<admintpl file="header"/>

<script src="__PUBLIC__/js/common.js"></script>

</head>
<body>
<div class="wrap">
    <form method="post" class="form-horizontal " id="myform"  action="{:U('Admin/NewsSet/liverolePost')}">
        <div class="containerr">

            <div style="width: 600px; margin-left: 20px; margin-bottom: 15px;">
                <span style="width: 80px; margin-top: 5px; float: left;">直播权限 </span>
                <select id="live_status" class="select_2" name="live_status">
                    <option <if condition="$live_status eq 0"> selected </if> value="0">关闭</option>
                    <option <if condition="$live_status eq 1"> selected </if> value="1">开启</option>
                </select>
            </div>
            <div class="span3" style="width: 630px;">
                <span style="width: 80px; margin-top: 10px; float: left;">设置管理员 </span>
                <input type="hidden" name="column_id" id="column_id" value="<?php echo $column_id;?>">
                <input type="hidden" name="admin_hidden_ids" id="admin_hidden_ids"  value="<?php echo $live_ids_arr ? implode(',',$live_ids_arr).',' : '';?>">
                <input type="hidden" name="column_type" id="column_type"  value="<?php echo $column_type ? $column_type : 0;?>">

                <input type="text"  style="width: 500px; float: left;" name="administrators" id="administrator" readonly="readonly" value="<?php if($live_status == 1) echo $live_arr ? implode(',',$live_arr).',' : '';?>">
            </div>

        </div>

        <div class="control-group" style="margin-top: 50px;">
            <label class="span1 control-label" style="width: 90px;"></label>
            <div class="span3">
                <foreach name="arr_mer" key="admin_key" item="admin_value">
                    <input  admin_name="{$admin_value}" name="admin_checkbox"  type="checkbox" value="{$admin_key}" <?php if(in_array($admin_key,$live_ids_arr) && $live_status == 1) echo 'checked="checked"'; ?> />{$admin_value}<br/>
                </foreach>
            </div>
        </div>


        <div class="form-actions" style="padding-left:260px;">
            <a class="btn btn-primary" id="ajaxform">提 交</a>
            &nbsp;&nbsp;<a class="btn" id="ajaxback">{:L('BACK')}</a>
        </div>
    </form>
</div>

<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script type="text/javascript">
    $(function(){
        $("[name='admin_checkbox']").click(function(){
            var admin_id = $(this).val();
            var admin_name = $(this).attr('admin_name');

            var admin_hidden_ids = $("#admin_hidden_ids").val();
            var admin_values = $("#administrator").val();

            var ids_arr = admin_hidden_ids.split(",");
            var values_arr = admin_values.split(",");


            if(ids_arr.indexOf(admin_id) == '-1'){

                admin_hidden_ids+=admin_id+',';
                admin_values+=admin_name+',';
                $("#administrator").val(admin_values);
                $("#admin_hidden_ids").val(admin_hidden_ids);
            }else{

                $.each(ids_arr,function(index,item){

                    if(item==admin_id){
                        ids_arr.splice(index,1);
                        values_arr.splice(index,1);
                    }
                })
                admin_hidden_ids = ids_arr.join(",");
                admin_values = values_arr.join(",");
                $("#administrator").val(admin_values);
                $("#admin_hidden_ids").val(admin_hidden_ids);
            }
        })
    })


    // ajax 提交表单
    $(document).ready(function(){
        $("#ajaxform").click(function(){    // 提交按钮触发事件
            var tourl = $("#myform").attr("action");    // 获取 表单的 提交地址
            var column_id = $("#column_id").val();
            var admin_hidden_ids = $("#admin_hidden_ids").val();
            var live_status      = $("#live_status").val();
            var column_type      = $("#column_type").val();

            $.post(tourl,{admin_hidden_ids:admin_hidden_ids,column_id:column_id,live_status:live_status,column_type:column_type},function(result){
                if(result == '1'){
                    var msg = '编辑成功';
                }else{
                    var msg = '编辑失败';
                }

                parent.layer.msg(msg,{time:2000},1,function(a){

                });
                setTimeout(function(){
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 1000);
            });
        });
        $("#ajaxback").click(function(){
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        });
    });
</script>
</body>
</html>